package com.matt.domain.course;

import com.matt.commons.exception.BusinessException;

import com.matt.commons.model.Model;
import com.matt.foundation.model.ErrorCode;
import com.matt.foundation.utils.ModelUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/3/8
 * *******************************
 */
@Entity
@Table(name = "course_topic")
@Data
@EqualsAndHashCode(callSuper = true)
public class CourseTopic extends Model {

    @Column(columnDefinition = "datetime  COMMENT '主题月份'")
    private Date topicMonth;

    @Column(columnDefinition = " datetime  COMMENT ' 开始时间 ' ")
    private Date beginDate;

    @Column(columnDefinition = " datetime  COMMENT ' 截止时间 ' ")
    private Date endDate;

    @Column(columnDefinition = "varchar(50)  COMMENT '名称'")
    private String name;

    @Column(columnDefinition = "varchar(32) COMMENT '适用对象id'")
    private String targetObjectId;

    @Column(columnDefinition = "longtext  COMMENT '描述'")
    private String description;

    @Column(columnDefinition = "varchar(1024)  COMMENT '描述'")
    private String imgUrls;

    @Column(columnDefinition = "varchar(32)  COMMENT '创建人'")
    private String createId;

    @Column(columnDefinition = "int default 0 COMMENT '状态' ")
    private Integer status = 0;

    @Column(columnDefinition = " datetime  COMMENT '创建时间' ")
    private Date created = new Date();

    @Column(columnDefinition = "longtext comment '附件'")
    private String attachments;
    
    public CourseTopic merge(CourseTopic courseTopic) {
        try {
            ModelUtil.copyNotNullPropertiesExcludeId(this, courseTopic);
        } catch (Exception e) {
            throw new BusinessException(ErrorCode.ENTITY_MERGE_ERROR, "拷贝属性出错");
        }
        return this;
    }
}
